package edu.ccut.saturn.studio.logic.model.drop.action;

import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;

import edu.ccut.saturn.studio.logic.model.drop.DropHandler;
import edu.ccut.saturn.studio.logic.model.drop.DropHandlerFactory;


public class ActionDropHandleFactory extends DropHandlerFactory {
	private static final String HANDLER_FILE_NAME = "action_drop_handles.properties";
	@SuppressWarnings("unchecked")
	@Override
	protected void initalDropHandle() {
		super.dropHandleMap = new HashMap<String, DropHandler>();
		
		Properties properties = new Properties();
		
		InputStream in = null;
		
		try {
			in = ActionDropHandleFactory.class.getResourceAsStream(HANDLER_FILE_NAME);
			properties.load(in);
			
			Enumeration enumeration = properties.propertyNames(); 
			while (enumeration.hasMoreElements()) {
				String key = (String)enumeration.nextElement();
				String classType = properties.getProperty(key);
				
				DropHandler handler = (DropHandler)Class.forName(classType).newInstance();
				super.dropHandleMap.put(key, handler);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
